import 'package:flutter/material.dart';

void main(){
  runApp(NavExample());
}
class NavExample extends StatefulWidget {
  const NavExample({super.key});

  @override
  State<NavExample> createState() => _NavExampleState();
}

class _NavExampleState extends State<NavExample> {
  int _selectedIndex = 0;

  static const List<Widget> _widgetOptions = <Widget>[
    Text('主页内容', style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
    Text('收藏内容', style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
    Text('设置内容', style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold)),
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('NavigationBar 示例'),
      ),
      body: Center(
        child: _widgetOptions.elementAt(_selectedIndex),
      ),
      bottomNavigationBar: NavigationBar(
        selectedIndex: _selectedIndex,
        
        onDestinationSelected: (int index) {
          setState(() {
            _selectedIndex = index;
          });
        },
        destinations: const <NavigationDestination>[
          NavigationDestination(
            selectedIcon: Icon(Icons.home),
            icon: Icon(Icons.home_outlined),
            label: '主页',
          ),
          NavigationDestination(
            selectedIcon: Icon(Icons.favorite),
            icon: Icon(Icons.favorite_border),
            label: '收藏',
          ),
          NavigationDestination(
            selectedIcon: Icon(Icons.settings),
            icon: Icon(Icons.settings_outlined),
            label: '设置',
          ),
        ],
        // 可以自定义指示器颜色
        // indicatorColor: Colors.deepPurple[100],
        // labelBehavior: NavigationDestinationLabelBehavior.onlyShowSelected,
      ),
    );
  }
}
